package com.zhongge.arrayOJ;

/**
 * @ClassName RemoveDuplicates
 * @Description TODO 删除排序数组中的重复项
 * @Author 笨忠
 * @Date 2025/8/7 20:36
 * @Version 1.0
 */
public class RemoveDuplicates {
    public static int removeDuplicates(int[] nums) {
        //首先看参数是否合法==》这是我们写程序的一个必修课
        if (nums == null) {
            return 0;
        }
        //在o(N)时间内完成说明就需要我们使用双指针
        int slow = 0;
        int fast = 0;
        while (fast < nums.length) {
            if (nums[slow] != nums[fast]) {
                slow++;
                nums[slow] = nums[fast];
                fast++;
            } else {
                fast++;
            }
        }
        return slow + 1;
    }

    public static void main(String[] args) {
        int[] nums = {0, 0, 1, 1, 1, 2, 2, 3, 3, 4};
        int slow = removeDuplicates(nums);
        for (int i = 0; i < slow; i++) {
            System.out.print(nums[i] + " ");
        }
        System.out.println();
    }
}
